/*
 * PayWay.java
 * business
 *
 * Created by ChenTao on 2017/2/22.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.data.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

/**
 * 支付方式Model
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/22 9:49
 */
public class PayWay implements ITag, Parcelable {

    /**
     * 支付去到
     */
    public interface Flavor {
        /**
         * 货到付款
         */
        String PAY_ON_DELIVERY = "cod";

        /**
         * 银行转账
         */
        String TRANSFER = "bank";

        /**
         * 在线支付
         */
        String ONLINE = "online";

        /**
         * POS机支付
         */
        String POS = "pos";
    }

    private String id;

    @SerializedName("is_enable")
    private int isEnable;

    @SerializedName("pay_code")
    private String payCode;

    @SerializedName("pay_name")
    private String name;

    @SerializedName("is_default")
    private int isDefault;

    /**
     * 当前支付方式的手续费
     */
    @SerializedName("pay_fee")
    private float payFee;

    /**
     * 手续费的上线. <em>-1:表示无上线</em>
     */
    @SerializedName("upper_limit")
    private float upperLimit;

    @SerializedName("pay_icon")
    private String payIcon;

    private boolean canChoose;

    @SerializedName("supplier_id")
    private String supplierId;

    @SerializedName("text")
    private String text;

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(String supplierId) {
        this.supplierId = supplierId;
    }

    private int getIsEnable() {
        return isEnable;
    }

    private void setIsEnable(int isEnable) {
        this.isEnable = isEnable;
    }

    public String getPayIcon() {
        return payIcon;
    }

    public void setPayIcon(String payIcon) {
        this.payIcon = payIcon;
    }

    public boolean isCanChoose() {
        return canChoose;
    }

    public void setCanChoose(boolean canChoose) {
        this.canChoose = canChoose;
    }

    private int getIsDefault() {
        return isDefault;
    }

    private void setIsDefault(int isDefault) {
        this.isDefault = isDefault;
    }

    public float getPayFee() {
        return payFee;
    }

    public void setPayFee(float payFee) {
        this.payFee = payFee;
    }

    public float getUpperLimit() {
        return upperLimit;
    }

    public void setUpperLimit(float upperLimit) {
        this.upperLimit = upperLimit;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPayCode() {
        return payCode;
    }

    public void setPayCode(String payCode) {
        this.payCode = payCode;
    }

    @Override
    public void setEnable(boolean enable) {
        setIsEnable(enable ? 1 : 0);
    }

    @Override
    public boolean isEnable() {
        // 默认等于1就是可操作
        return getIsEnable() == 1;
    }

    @Override
    public boolean isSelected() {
        // 对服务器的数据进行转化
        return getIsDefault() == 1;
    }

    @Override
    public void setSelected(boolean selected) {
        // 对服务器给的数据进行转化
        setIsDefault(selected ? 1 : 0);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PayWay payWay = (PayWay) o;

        return payCode != null ? payCode.equals(payWay.payCode) : payWay.payCode == null;
    }

    @Override
    public int hashCode() {
        return payCode != null ? payCode.hashCode() : 0;
    }

    public PayWay() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.payCode);
        dest.writeString(this.name);
        dest.writeInt(this.isDefault);
        dest.writeFloat(this.payFee);
        dest.writeFloat(this.upperLimit);
        dest.writeString(this.payIcon);
        dest.writeByte(this.canChoose ? (byte) 1 : (byte) 0);
    }

    protected PayWay(Parcel in) {
        this.id = in.readString();
        this.payCode = in.readString();
        this.name = in.readString();
        this.isDefault = in.readInt();
        this.payFee = in.readFloat();
        this.upperLimit = in.readFloat();
        this.payIcon = in.readString();
        this.canChoose = in.readByte() != 0;
    }

    public static final Creator<PayWay> CREATOR = new Creator<PayWay>() {
        @Override
        public PayWay createFromParcel(Parcel source) {
            return new PayWay(source);
        }

        @Override
        public PayWay[] newArray(int size) {
            return new PayWay[size];
        }
    };
}
